package com.uhomecp.lambda.biaodashi1;

public class Java8Tester1 {

    public static void main(String[] args) {
        Java8Tester1 tester1 = new Java8Tester1();
        // 类型声明
        MathOperation addition1 = (int a, int b) -> a + b;
        System.out.println(addition1.operation(1,2));

        // 不用类型声明
        MathOperation subition2 = (a,b)->a-b;
        System.out.println(subition2.operation(1,2));

        // 大括号中的返回语句
        MathOperation muthition = (a,b)->{return a*b;};
        System.out.println(muthition.operation(1,2));

        // 没有大括号及返回语句
        MathOperation division = (int a, int b) -> a / b;
        System.out.println("10 / 5 = " + tester1.operate(10, 5, division));

        // 不用括号
        GreetingService greetingService1 = message -> System.out.println("hello " + message);
        greetingService1.sayMessage("abc1 ");

        // 用括号
        GreetingService greetingService2 = (message) -> System.out.println("hello " + message);
        greetingService2.sayMessage("abc2 ");
    }

    interface MathOperation{
        int operation(int a, int b);
    }

    interface GreetingService {
        void sayMessage(String message);
    }

    private int operate(int a, int b, MathOperation mathOperation){
        return mathOperation.operation(a, b);
    }
}
